package com.lv.suyiyong.hfrwork.adapter

import android.graphics.Color
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.blankj.utilcode.util.SizeUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lv.common.imp.OnPositionTListener
import com.lv.common.utils.MyUtils.mContext
import com.lv.service.bean.UserInfoTabBean
import com.lv.suyiyong.hfrwork.R

/**
 * 作者： ygx
 * 创建日期：2022/6/24 8:10 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 *
 */
class UserInfoTabAdapter(private val datas: MutableList<UserInfoTabBean>?) :
    BaseQuickAdapter<UserInfoTabBean, BaseViewHolder>
        (R.layout.user_info_tab_item, datas) {

    override fun convert(helper: BaseViewHolder, item: UserInfoTabBean) {
        val layoutPosition = helper.layoutPosition
        val clParent: ConstraintLayout = helper.getView<ConstraintLayout>(R.id.cl_parent)
        val tv_name = helper.getView<TextView>(R.id.tv_name)
        val tv_target = helper.getView<TextView>(R.id.tv_target)
        val tv_scene = helper.getView<TextView>(R.id.tv_scene)
        val tv_collect = helper.getView<TextView>(R.id.tv_collect)
        val tv_content = helper.getView<TextView>(R.id.tv_content)
//        TextView view_empty = helper.getView(R.id.view_empty);
        //        TextView view_empty = helper.getView(R.id.view_empty);
        tv_content.setTextColor(
            mContext.getResources().getColor(com.lv.common.R.color.color_EB613D)
        )
        tv_name.paint.isFakeBoldText = true
        tv_name.text = item.name
        tv_target.text = item.target
        tv_scene.text = item.scene
        tv_collect.text = item.collect
        tv_content.text = item.content
        if (layoutPosition % 2 == 0) {
            tv_name.setBackgroundColor(Color.parseColor("#fafafa"))
            tv_target.setBackgroundColor(Color.parseColor("#fafafa"))
            tv_scene.setBackgroundColor(Color.parseColor("#fafafa"))
            tv_collect.setBackgroundColor(Color.parseColor("#fafafa"))
            tv_content.setBackgroundColor(Color.parseColor("#fafafa"))
        } else {
            tv_name.setBackgroundColor(mContext.resources.getColor(R.color.white))
            tv_target.setBackgroundColor(mContext.resources.getColor(R.color.white))
            tv_scene.setBackgroundColor(mContext.resources.getColor(R.color.white))
            tv_collect.setBackgroundColor(mContext.resources.getColor(R.color.white))
            tv_content.setBackgroundColor(mContext.resources.getColor(R.color.white))
        }
        val layoutParams = clParent.layoutParams as LinearLayout.LayoutParams
        if (layoutPosition == data.size) {
//            view_empty.setVisibility(View.VISIBLE);
            layoutParams.bottomMargin = SizeUtils.dp2px(40.0f)
        } else {
//            view_empty.setVisibility(View.GONE);
            layoutParams.bottomMargin = SizeUtils.dp2px(0.0f)
        }
        clParent.layoutParams = layoutParams
        clParent.setOnClickListener(View.OnClickListener {
            onViewClickListener?.onClick(layoutPosition,item.name)
        })
    }

    var onViewClickListener: OnPositionTListener<String>? = null


}